package cn.good.yan.controller.t2;

import cn.good.yan.service.t2.RedService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 演示 - Redis - 抢红包
 *
 * @author shengren.yan
 * @create 2023-12-12
 */
@RestController
@RequestMapping("/t2")
@Slf4j
@Api(tags = "抢红包接口")
public class RedController {

    @Autowired
    private RedService redService;

    /**
     * 发红包
     * @param totalMoney       金额
     * @param redPackageNumber 红包个数
     * @return {@link String}
     */
    @ApiOperation("发红包")
    @GetMapping("/send")
    public String send(int totalMoney, int redPackageNumber) {
        // 返回红包的key
        String str = redService.sendRedPackage(totalMoney, redPackageNumber);
        return str;
    }

    /**
     * 抢红包
     * @param redPackageKey  哪个红包的key
     * @param userId         用户id
     * @return {@link String}
     */
    @ApiOperation("抢红包")
    @GetMapping("/rob")
    public String rob(String redPackageKey, String userId) {
        String str = redService.robRedPackage(redPackageKey, userId);
        return str;
    }

}
